package com.nd.android.u.ui.widge;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;

//基础类
public class Action {
	protected static final String TAG = "Action";
	public int color;
	public Path path;
	public float size;
	public Paint paint;

	Action() {
		color=Color.BLACK;
		paint = new Paint();
		path = new Path();
	}

	Action(int color) {
		this.color = color;
		paint = new Paint();
		path = new Path();
	}

	public void draw(Canvas canvas) { }
	
	public void lineTo(float x,float y){
		path.lineTo(x, y);
		path.reset();
	}
	
	public void quadTo(float x1,float y1,float x2,float y2){
		path.quadTo(x1, y1, x2, y2);
	}

	public Path getPath() {
		return path;
	}

	public Paint getPaint() {
		return paint;
	}
}

// 自由曲线
class MyPath extends Action {
	protected static final String TAG = "MyPath";
	MyPath() {
		path=new Path();
		size=1;
	}

	MyPath(float x,float y,float size, int color) {
		super(color);
		this.size=size;
		path.reset();
		path.moveTo(x, y);
	}
	
	public void draw(Canvas canvas) {
		paint.setAntiAlias(true);
		paint.setDither(false);
		paint.setColor(color);
		paint.setStrokeWidth(size);
		paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeJoin(Paint.Join.ROUND);
        paint.setStrokeCap(Paint.Cap.ROUND);
        canvas.drawPath(path, paint);
	}
}

//橡皮
class MyEraser extends Action {
	
	MyEraser() {
		path=new Path();
		size=1;
	}

	MyEraser(float x,float y,int size, int color) {
		super(color);
		this.size=size;
		path.reset();
		path.moveTo(x, y);
	}
	
	public void draw(Canvas canvas) {
		paint.setAntiAlias(true);
        paint.setDither(false);
        paint.setColor(Color.WHITE);
        paint.setStrokeWidth(size);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeJoin(Paint.Join.ROUND);
        paint.setStrokeCap(Paint.Cap.SQUARE);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
        canvas.drawPath(path, paint);
	}
}